﻿using Microsoft.Extensions.DependencyInjection;

namespace Tszy.Unlimited.Base.BackgroundTasks;

/// <summary>
/// 
/// </summary>
public static class BackgroundWorkerServiceCollectionExtensions
{
    /// <summary>
    /// 注册后台任务。
    /// </summary>
    /// <typeparam name="TService"></typeparam>
    /// <param name="services"></param>
    /// <returns></returns>
    public static IServiceCollection RegisterBackgroundTask<TService>(this IServiceCollection services) where TService : class, IBackgroundProcessingService
    {
        services.AddScoped<TService>();
        services.AddHostedService<ScopedBackgroundService<TService>>();
        return services;
    }
}